Add ofEntries static method to Map interfaces#330
Merged
vigna merged 2 commits intovigna:masterfrom Jun 21, 2025
Merged
Conversation
drv/Map.drv
Outdated
| if (entries.length <= 8) { | ||
| return MAPS.unmodifiable(new ARRAY_MAP KEY_VALUE_GENERIC_DIAMOND(keys, vals, entries.length)); | ||
| } else { | ||
| return MAPS.unmodifiable(new OPEN_HASH_MAP KEY_VALUE_GENERIC_DIAMOND(keys, vals, 0.75f)); |
Collaborator
There was a problem hiding this comment.
this creates the keys / values array unnecessarily. I think the code should be like
if (number of entries is small)
create keys and vals as above (with duplicate checking)
return array map with keys and vales
else
create appropriately sized hash map
for each entry:
if map.put(entry.key, entry.value) != null then throw exception
return hash map
Contributor
Author
There was a problem hiding this comment.
you are quite right, let me do that
Contributor
Author
There was a problem hiding this comment.
would using contains instead of the return value of #put be better? For the edge case where the previous value is null
8a80c92 to
6f24bb2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pretty simple PR, I think
Things to note:
entry(key, value)static method was also added to make it easier to use, just likejava.util.MapInt2IntMapTestbecause I would have put the same things I did inObject2ObjectMapTestClose #329